Segmenting a Flatfish by Texture

Instructions are in the task pane to the left. Complete and submit each task one at a time.
This code sets up the activity.
flatFish = imread("./images/flatfish.jpg");
imshow(flatFish)

Task 1

The first step is to convert the image to grayscale with im2gray.
fishGray = im2gray(flatFish);
imshow(fishGray)

Task 2

Use stdfilt to apply a standard deviation filter to fishGray.
imSF = stdfilt(gs);
fishSTD = stdfilt(fishGray);
imshow(fishSTD)

Task 3

The stdfilt function automatically converted the image to a double array for increased precision in the calculation. The standard deviations of values from 0 to 255 are outside of the range 0 to 1, so the entire image was saturated and appears white.
You will need to rescale your image so the values are between 0 and 1 using the rescale function.
fishSTD = rescale(fishSTD);
imshow(fishSTD)

Task 4

Use rangefilt to apply a range filter to fishGray.
J = rangefilt(I)
The function rangefilt does not convert the image to a different data type. Because the range is calculated by subtracting the maximum and the minimum, the output values are still integers, so you do not need to rescale the result.
fishRNG = rangefilt(fishGray);
imshow(fishRNG)

Task 5

Use entropyfilt to apply an entropy filter to fishGray.
J = entropyfilt(I)
Like the stdfilt function, the output of entropyfilt is of type double and needs to be rescaled for visualization.
fishENT = entropyfilt(fishGray);
fishENT = rescale(fishENT);
imshow(fishENT)

Task 6

The image filtered with standard deviation does a good job of creating contrast between the fish and the background, so let's create a segmentation based on that image.
One way to segment a grayscale image is with the imbinarize function.
BW = imbinarize(gs);
The output BW is a binary image where foreground pixels have value 1 and background pixels have value 0.
fishBW = imbinarize(fishSTD);
imshow(fishBW)